/* File: Gene.java
 * Purpose: Represents a gene for an organism.
 * Author: Team Karp
 * Date: 12/13/07
 * Revisions: 12/13/07 - Initial Version - Adam Patterson
 *            2007-12-20, Ryan J. Bovorasmy - Started implementing.
 *            2008-1-20, Paul Kratt - Added name field, because it's useful to know what a gene does.
 * Additional Requirements:
 */
package protovitae.data;

import java.util.ArrayList;
import java.util.Enumeration;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * Represents a gene.
 * Implements Organism because all Organism methods are decorated by genes
 * @version 1.0
 * @created 06-Dec-2007 16:19:09
 */
public class Gene implements Organism,MutableTreeNode,XMLSavable {
    private ConcreteOrganism parent;
    protected String name="New gene"; //Name of this Gene.
    
    /**
     * Default constructor.
     */
    public Gene(){
        init(null, null);
    }
    
    public String getGeneticInformation() {
        return name;
    }
    
    /**
     * This may not be used, check EA diagram.
     * @param organism
     * @param attribute
     */
    public void init(Organism organism, Organism.ATTRIBUTE_TYPE attribute){
        
    }
    
    /**
     * Copy constructor.
     * @param parent
     */
    public void Gene(Gene right){
        this.setParent(right.getParent());
    }
    
    /**
     * Code override for attacking another organism.
     * @param organism The organism to attack.
     */
    public void attack(Organism organism){
        System.out.println("GENE ATTACK");
    }
    
    /**
     * Code override for determining which action to take
     * @param parentSimulation
     * @param parentOrganism
     * @return - the ACTION and the target ConcreteOrganism
     */
    public ArrayList act(Simulation parentSimulation,Organism parentOrganism){
        return null;
    }
    
    /**
     *
     * @param organism
     */
    public void dance(Simulation parent, Organism organism){
        System.out.println("GENE DANCE");
    }
    
    /**
     *
     * @param food
     */
    public void eat(Organism food){
        System.out.println("GENE EAT");
    }
    
    /**
     *
     * @param action
     */
    public void execute(Organism.ACTION_TYPE action){

    }
    
    public int getDominance(){
        return 0;
    }
    
    /**
     *
     * @param organism
     */
    public void mate(Organism organism){
        
    }
    
    /**
     * @param parent
     */
    public Position move(Simulation parent, ConcreteOrganism organism){
        return null;
    }
    
    /**
     * @param parent
     */
    public void save(Element parentElm, Document doc){
        
    }

    public void load(Element input) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
    
    /**
     *
     */
    public ConcreteOrganism getParent() {
        return parent;
    }
    
    /**
     *
     */
    public void setParent(ConcreteOrganism parent) {
        this.parent = parent;
    }

    /** Get the name of this trait.
     * @return The name that describes this trait.
     */
    public String getName() {
        return name;
    }
    
    /** Get the name of this trait.
     * @return The name that describes this trait.
     */
    @Override
    public String toString() {
        return name;
    }

    /** Set the name of this trait.
     * @param name The new name
     */
    public void setName(String name) {
        this.name = name;
    }

    public void insert(MutableTreeNode child, int index) {
        //Not supported.
    }

    public void remove(int index) {
        //Not supported
    }

    public void remove(MutableTreeNode node) {
        //No children, no way.
    }

    /** Remove self from parent. ***/
    public void removeFromParent() {
        parent.remove(this);
    }

    public void setParent(MutableTreeNode newParent) {
        this.parent = (ConcreteOrganism)newParent;
    }

    public void setUserObject(Object object) {
        //Not supported
    }

    public Enumeration children() {
        return null; //Not supported
    }

    public boolean getAllowsChildren() {
        return false; //No, we are a leaf
    }

    public TreeNode getChildAt(int childIndex) {
        return null; //I'm a leaf
    }

    public int getChildCount() {
        return 0; //No children
    }

    public int getIndex(TreeNode node) {
        return -1; //Does not exist
    }

    public boolean isLeaf() {
        return true; //Yes, I'm always a leaf.
    }
    
}